﻿
Imports std
Imports managedServer
Imports storoomc

Public Module roomview

    Public Const defaultConfigfile As String = "roomview.ini"
    Public Const applicationName As String = "roomview"
    Public rooms As vector(Of room) = Nothing

    Public Sub main(ByVal args() As String)
        ProHttpS.managedRequestProcessors().insert(New globalInitial())
        ProHttpS.managedRequestProcessors().insert(New listview())
        ProHttpS.managedRequestProcessors().insert(New keyview())
        ProHttpS.managedRequestProcessors().insert(New roomstatus())
        ProHttpS.managedRequestProcessors().insert(New homepage())
        ProHttpS.defaultConfigfile = defaultConfigfile
        ProHttpS.startServer(args, configNaming.roomview.name, New httpContext.parameterDefinition(stringsPackage:=sp))
    End Sub

    Public Function talk(ByVal host As String, ByVal port As Int32) As storoomTalk
        talk = storoomTalks.get(host, port)
        If Not talk Is Nothing Then
            talk.holdTime = 60000
        End If
        Return talk
    End Function
End Module

Public Class room
    Public name As String = Nothing
    Public host As String = Nothing
    Public port As Int32 = 0

    Public Shared Function parse(ByVal i As String) As room
        Dim words As vector(Of String) = Nothing
        strsepar(i, character.comma, words)
        If Not words Is Nothing AndAlso words.size() >= 3 Then
            Dim rtn As room = Nothing
            rtn = New room()
            copy(rtn.name, words(0))
            copy(rtn.host, words(1))
            If Not convertor.toint32(words(2), rtn.port) Then
                Return Nothing
            End If

            Return rtn
        Else
            Return Nothing
        End If
    End Function
End Class

Namespace query
    Public Module query
        Public Const host As String = "h"
        Public Const port As String = "p"
        Public Const key As String = "k"
    End Module
End Namespace

Namespace configNaming
    Namespace roomview
        Public Module roomview
            Public Const name As String = "roomview"
            Public Const room As String = "room"
        End Module
    End Namespace

    Namespace defaultValue
        Namespace roomview
            Public Module roomview

            End Module
        End Namespace
    End Namespace
End Namespace
